package com.example.suhui_test;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 用户数据传输对象
 * 实现Parcelable接口以支持AIDL传输
 */
public class User implements Parcelable {
    private int id;
    private String name;
    private String email;

    /**
     * 默认构造函数
     */
    public User() {
    }

    /**
     * 带参数的构造函数
     */
    public User(int id, String name, String email) {
        this.id = id;
        this.name = name;
        this.email = email;
    }

    /**
     * 从Parcel中读取数据
     */
    protected User(Parcel in) {
        id = in.readInt();
        name = in.readString();
        email = in.readString();
    }

    /**
     * 创建Parcelable对象
     */
    public static final Creator<User> CREATOR = new Creator<User>() {
        @Override
        public User createFromParcel(Parcel in) {
            return new User(in);
        }

        @Override
        public User[] newArray(int size) {
            return new User[size];
        }
    };

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(name);
        dest.writeString(email);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    // Getters和Setters
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", email='" + email + '\'' +
                '}';
    }
}